package com.project.dao.impl;

import com.project.bean.CityBean;
import com.project.bean.CountryBean;
import com.project.dao.ICityDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
@Repository
public class CityDaoImpl extends BaseDao implements ICityDao {
    @Override
    public List<CityBean> findById(int countryId) {

        List<CityBean> list = new ArrayList<>();
        this.setConnection();
        try {
            ps = con.prepareStatement("select * from t_city where fk_contryId=?");
            ps.setObject(1, countryId);

            rs = ps.executeQuery();
            while (rs.next()) {
                CityBean city = new CityBean();
                city.setId(rs.getInt("pk_cityId"));
                city.setName(rs.getString("t_naem"));
                CountryBean country = new CountryBean();
                country.setId(rs.getInt("fk_contryId"));
                city.setCountry(country);
                list.add(city);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            this.closeConnection();
        }
        return list;
    }
}
